package com.bangcommunity.bbframe.sdm.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.io.IOException;

public class PathMatchUtils {

    static Logger logger = LoggerFactory.getLogger(PathMatchUtils.class);
    private static PathMatcher matcher = new AntPathMatcher();

    public static boolean isAntPathMatch(String path, String patternPath) {
        return matcher.match(patternPath, path);
    }

    public static void main(String[] args) throws IOException {
        // 完全路径匹配
        System.out.println(isAntPathMatch("/app/pub/login.do", "/**/login.do"));
        System.out.println(isAntPathMatch("/app/pub/login.do", "/**/pub/login.do"));
        System.out.println(isAntPathMatch("/app/pub/login.do", "/**/app/pub/login.do"));
        // 不完整路径匹配
        System.out.println(isAntPathMatch("/user/list.htm?username=aaa&id=2&no=1&page=20", "/user/list.htm*"));
        // 模糊路径匹配
        System.out.println(isAntPathMatch("/app/pub/login.do", "/**/*.do"));
        // 模糊单字符路径匹配
        System.out.println(isAntPathMatch("/app/pub/login.do", "/**/lo?in.do"));
        // 不匹配
        System.out.println(isAntPathMatch("/app/pub/login.do", "/ddd/pub/*"));
    }
}
